﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bluyel.Core
{
    /// <summary>
    /// Represents a string data value.
    /// Not null a the start, is set to an empty string.
    /// </summary>
    public class ValueString : ValueBase, IValueBasic
    {
        /// <summary>
        /// The string data value.
        /// </summary>
        private string _value;

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="value"></param>
        public ValueString()
        {
            //this.DataValueType = DataValueType.String;

            // init to empty (not to null)
            _value = "";
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="value"></param>
        public ValueString(string value)
        {
            //this.DataValueType = DataValueType.String;
            _value = value;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Set a new string value. 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public bool SetValue(string val)
        {
            // can be null?
            // todo:

            _value = val;
            return true;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Return the string value.
        /// </summary>
        /// <returns></returns>
        public string GetValue()
        {
            return _value;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// return true 
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public override bool IsEqualsTo(IValue dv)
        {
            ValueString dvStr = dv as ValueString;
            if (dvStr == null)
                return false;

            // check that both  dv value are not null
            // TODO:

            return GetValue().Equals(dvStr.GetValue());
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// return true 
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public bool IsEqualsTo(ValueString dv)
        {
            if (dv == null)
                return false;

            // check that both  dv value are not null
            // TODO:
            return GetValue().Equals(dv.GetValue());
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// return true 
        /// </summary>
        /// <param name="dv"></param>
        /// <returns></returns>
        public bool IsEqualsTo(string s)
        {
            if (s == null)
                return false;

            // check that dv value is not null
            // TODO:
            return GetValue().Equals(s, StringComparison.InvariantCultureIgnoreCase);
        }


        //---------------------------------------------------------------------
        public override string ToString()
        {
            return "str: " + _value;
        }
    }
}
